package com.jingsheng.jingshengcity.mvp.ui.activity;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.app.utils.BitmapUtil;
import com.jingsheng.jingshengcity.app.utils.DensityUtil;
import com.jingsheng.jingshengcity.di.component.DaggerConfirmOrderComponent;
import com.jingsheng.jingshengcity.di.module.ConfirmOrderModule;
import com.jingsheng.jingshengcity.mvp.contract.ConfirmOrderContract;
import com.jingsheng.jingshengcity.mvp.presenter.ConfirmOrderPresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.ConfirmOrderActivityAdapter;
import com.jingsheng.jingshengcity.widgets.decoration.GridItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/10.
 */

public class ConfirmOrderActivity extends BaseActivity<ConfirmOrderPresenter> implements ConfirmOrderContract.View {

    @NonNull
    @BindView(R.id.iv_splite_line)
    ImageView mIvLine;
    @NonNull
    @BindView(R.id.rv_list)
    RecyclerView mRecyclerView;

    private List<String> mList = new ArrayList<>();

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerConfirmOrderComponent
                .builder()
                .appComponent(appComponent)
                .confirmOrderModule(new ConfirmOrderModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        setTitle("确认订单");
        return R.layout.activity_confirm_order;
    }

    @Override
    public void initData() {
        Resources res = getResources();
        Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.img_splite_line);
        mIvLine.setImageBitmap(BitmapUtil.createRepeater(DensityUtil.getScreenSize(this).x, bitmap));//screenWidth为屏幕宽度（或显示图片的imageview宽度）

        mList.add("1");
        mList.add("1");
        mList.add("1");

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        ConfirmOrderActivityAdapter mConfirmOrderActivityAdapter = new ConfirmOrderActivityAdapter(R.layout.adapter_confirm_order_item, mList);
        mConfirmOrderActivityAdapter.openLoadAnimation();
        mRecyclerView.addItemDecoration(new GridItemDecoration(this, R.drawable.list_gray_divider_5));
        mRecyclerView.setAdapter(mConfirmOrderActivityAdapter);
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public boolean useFragment() {
        return false;
    }

}